import * as Constant from '../constants/Constant'

import fetch from 'isomorphic-fetch'


export function showNewsAll(news){
	return {
		type:Constant.NEWS_SHOW_ALL,
		news:news

	};
}

export function showNewsDetail(newsDetail){
	return{
		type:Constant.NEWS_DETAIL,
		newsDetail:newsDetail
	}
}


export function fetchNewsList() {
  return dispatch => {
    return fetch(ENV.baseUrl+'/news/list',{credentials: 'include'})
      .then(response => response.json())
      .then(json => dispatch(showNewsAll(json)))
  }
}


export function fetchNewsDetail(newsId){
	return dispatch =>{
		return fetch(ENV.baseUrl+'/news/'+newsId,{credentials:'include'})
		.then(response => response.json())
		.then(json => dispatch(showNewsDetail(json)))
	}
}
